@extends('layout.page')
@section('title','群体管理 - 列表')
@section('stylesheet')
    <link href="/css/custom.css" rel="stylesheet">
@endsection

@section('static-page')
    <div class="col-sm-12">
        <div class="ibox float-e-margins">
            <div class="ibox-title">
                <h5>群体管理<small></small></h5>
            </div>
            <div class="ibox-content">
                <div class="">
                    <a href="/ceb/community/create" class="btn btn-primary ">添加</a>
                </div>

                {{--搜索分页代码块--}}
                {{--<div class="row">
                    <label class="adha-pro-pagelable">每页显示</label>
                    <form action="" method="get">
                        <div class="col-sm-2 m-b-xs">
                            <select name="pageSize" class="input-sm form-control input-s-sm inline">
                                <option @if($pageSize==20) selected @endif value="20">20</option>
                                <option @if($pageSize==50) selected @endif value="50">50</option>
                                <option @if($pageSize==100) selected @endif value="100">100</option>
                            </select>
                        </div>
                        <label class="adha-pro-pagelable">条</label>
                        <div class="col-sm-3">
                            <div class="input-group">
                                <input name="searchVal" value="@if(!empty($searchVal)){{$searchVal}}@endif"
                                       type="text" placeholder="请输入关键词" class="input-sm form-control"> <span class="input-group-btn">
                                        <button type="submit" class="btn btn-sm btn-primary"> 搜索</button> </span>
                            </div>
                        </div>
                    </form>
                </div>--}}


                <table class="table table-striped table-bordered table-hover">
                    <thead>
                    <tr>
                        <th>ID</th>
                        <th>群体</th>
                        <th>描述</th>
                        <th>人数</th>
                        <th>筛选项</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    @foreach($userList as $info)
                        <?php $conditions = json_decode($info->conditions,true);?>
                        <tr class="gradeA">
                            <td>{{$info->id}}</td>
                            <td>{{$info->name}}</td>
                            <td>{{$info->description}}</td>
                            <td>
                                <div class="pull-left _loading" style="display: none">
                                    <div class="sk-spinner sk-spinner-fading-circle">
                                        <div class="sk-circle1 sk-circle"></div>
                                        <div class="sk-circle2 sk-circle"></div>
                                        <div class="sk-circle3 sk-circle"></div>
                                        <div class="sk-circle4 sk-circle"></div>
                                        <div class="sk-circle5 sk-circle"></div>
                                        <div class="sk-circle6 sk-circle"></div>
                                        <div class="sk-circle7 sk-circle"></div>
                                        <div class="sk-circle8 sk-circle"></div>
                                        <div class="sk-circle9 sk-circle"></div>
                                        <div class="sk-circle10 sk-circle"></div>
                                        <div class="sk-circle11 sk-circle"></div>
                                        <div class="sk-circle12 sk-circle"></div>
                                    </div>
                                </div>
                                <a href="javascript:void(0);" class="_get-count" data-val="{{$info->id}}">点击获取人数</a>
                            </td>
                            <td>{{$info->jsonToDescrition($info->conditions)}}</td>
                            <td class="center">
                                <a href="/ceb/community/edit?id={{$info->id}}">编辑</a>
                            </td>
                        </tr>
                    @endforeach

                    </tbody>
                    <tfoot>
                    <tr>
                        <th>ID</th>
                        <th>群体</th>
                        <th>描述</th>
                        <th>人数</th>
                        <th>筛选项</th>
                        <th>操作</th>
                    </tr>
                    </tfoot>
                </table>
                {{--分页--}}
                <div>
                    <div class="pull-right">
                        {{ $userList->appends(['pageSize'=>$pageSize])->render()  }}
                    </div>
                </div>
            </div>
        </div>
    </div>
@endsection

@section('javascript')
    <script>
        $(document).ready(function () {

            $('.delete-product').click(function () {
                var docuElem=$(this);
                var permissionId=docuElem.data('value');
                var title=docuElem.data('title');
                if(window.confirm('你确定删除'+ title+ '？')){
                    //继续执行
                    $.ajaxSetup({
                        headers: { 'X-CSRF-TOKEN' : '{{ csrf_token() }}' }
                    });
                    $.ajax({
                        type:'post',
                        url:'{{ url('/admin/permission/delete') }}',
                        dataType:'json',
                        data:{permissionId:permissionId},
                        success: function(data){
                            data=eval(data);
                            if(data.code==200){
                                layer.msg(data.message, {icon: 6});
                                docuElem.parents('.gradeA').remove();
                            }else{
                                layer.msg(data.message, {icon: 5});
                            }
                        }
                    });
                }
            });
            //====
            $("select[name='pageSize']").change(function () {
                $('form').submit();
            });
            
            $("._get-count").click(function () {

                var id = $(this).data('val');
                var dom_text = $(this);
                var dom_load = $(this).prev('._loading');

                $.ajax({
                    type:'get',
                    url:'/ceb/community/getCountById',
                    dataType:'json',
                    data:{id:id},
                    beforeSend:function () {
                        dom_text.hide();
                        dom_load.show();
                    },
                    success:function (data) {
                        console.log(data.code);
                        if(data.code == 1){
                            dom_text.show();
                            dom_text.unbind("click")
                            dom_text.html(data.data.count);
                        }
                        else{
                            dom_text.show();
                            dom_text.html("获取失败，重试");
                        }
                    },
                    complete:function () {
                        dom_load.hide();
                    }
                });
            });

            
        });

    </script>
@endsection

